package com.lmt_16;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Account {
    private String acount;
    private double money; // 余额
    private Lock lk = new ReentrantLock(); // 创建一个锁对象

    public Account(String acount, double money) {
        this.acount = acount;
        this.money = money;
    }


    public Account(){

    }

    public String getAcount() {
        return acount;
    }

    public void setAcount(String acount) {
        this.acount = acount;
    }

    public double getMoney() {
        return money;
    }

    public void setMoney(double money) {
        this.money = money;
    }

    public  void drawmoney(String name) {
       //synchronized (Account.class){
           try {
               lk.lock();
               if (this.money >= 100000){
                   System.out.println(name+"取出100000");
                   this.money-=100000;
                   System.out.println(name+"取钱后还剩"+this.money);
               }else {
                   System.out.println(name+"余额不足");
               }
           }catch (Exception e){
               e.printStackTrace();
           }finally {
               lk.unlock();
           }
       //}
    }
}
